//============================================================================
// Name        : bitmap.h
// Author      : Yugi
// Version     : 1.0
// Description : 
//============================================================================

#ifndef _BITMAP_H
#define _BITMAP_H

#include <stdlib.h>
#include <dr_api.h>

/* Structure of simple bitmap */
typedef struct _SBITMAP {
	char* data;
	unsigned int size;
} SBITMAP, *PSBITMAP;

/* 
* Generate a simple bitmap
* 
* REQUIRE:	bits greater than 0
* RETURN:	new bitmap
* NOTES:	Return value should be freed by user
*/
PSBITMAP bm_new(unsigned int bits);

/* 
* Reutrns a clone of the input bitmap
*
* REQUIRE:	pSrc not NULL
* RETURN:	a clone of pSrc
* NOTES:	Return value should be freed by user
*/
PSBITMAP bm_clone(PSBITMAP);

/* 
* Merge bitmap
*
* REQUIRE:	bitmap1 not NULL
*			bitmap2 not NULL
* RETURN:	bitmap merged from bitmap1 and bitmap2
* NOTES:	Return value should be freed by user
*/
PSBITMAP bm_merge(PSBITMAP bitmap1, PSBITMAP bitmap2);

/* 
* Free the memory hold by bitmap instance.
*
* REQUIRE:	pBitmap not NULL
* MODIFY:	pBitmap
*/
void bm_delete(PSBITMAP);

/* 
* Test if pBitmap1 and pBitmap2 are indistinguishable.
*
* REQUIRE:	pBitmap1, pBitmap2 not NULL, their data not NULL
* RETURN:	true if pBitmap1 and pBitmap2 are indistinguishable
*			false otherwise
*/
bool bm_equals(PSBITMAP, PSBITMAP);

/* 
* Set bit. 
*
* REQUIRE:	pBitmap not NULL, index / 8 less than pBitmap->size
* MODIFY:	pBitmap
*/
void bm_setbit(PSBITMAP pBitmap, unsigned int index);

/* 
* Clear bit.
*
* REQUIRE:	pBitmap not NULL, index / 8 less than pBitmap->size
* MODIFY:	pBitmap
*/
void bm_clearbit(PSBITMAP pBitmap, unsigned int index);

/* 
* Test bit.
*
* REQUIRE:	pBitmap not NULL, index / 8 less than pBitmap->size
* MODIFY:	pBitmap
*/
bool bm_testbit(PSBITMAP pBitmap, unsigned int index);

/* Print a bitmap */
void bm_print(PSBITMAP pBitmap, file_t outfile);

#endif /* End of _BITMAP_H */